import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * This class makes reference to the rocket bullet, one of the kinds of bullets on the game.
 * 
 * @author (Arturo Aaron Rios Obregon) 
 * @version (25 june 2013)
 */
public class Laser extends Bala
{
    private SimpleTimer timer;
    private GreenfootImage [] images;
    private int numImage;
    
    /**
     * Constructor
     */
    public Laser()
    {
        super(1);
        timer = new SimpleTimer();
        timer.mark();
        images = new GreenfootImage[4];
        images[0] = new GreenfootImage("laserAma.png");
        images[1] = new GreenfootImage("laserVerde.png");
        images[2] = new GreenfootImage("laserRojo.png");
        images[3] = new GreenfootImage("laserAzul.png");
        numImage=0;
        setImage(images[0]);        
    }
    
    
    /**
     * Act - do whatever the Laser wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        mueve();
        imagenes();        
        elimina();
         // Add your action code here.
    }
    
    /**
     * This method changes the images of the laser to give an effect of real laser.
     */
    public void imagenes()
    {                
        numImage+=1;
        numImage=numImage%4;
        setImage(images[numImage]);
    }
    
    /**
     * This method erase the object after of certain elapsed time.
     */
    public void elimina()
    {
        if(timer.millisElapsed()/100>5)
        {
            getWorld().removeObject(this);
            timer.mark();
        }
    }
    
    /**
     * Method which moves the laser depending of the position of the ship.
     */
    public void mueve()
    {
        int x = super.getX();
        int y = super.getY();
        if(Greenfoot.isKeyDown("up"))
            setLocation(x,y-7);
        if(Greenfoot.isKeyDown("down"))        
            setLocation(x,y+7);
        if(Greenfoot.isKeyDown("left"))        
            setLocation(x-7,y);        
        if(Greenfoot.isKeyDown("right"))        
            setLocation(x+7,y);
    }
    
}
